
var vm = new Vue({
    el : "#DadiOutofstock",
    data : {
        record:{},
        sels:[],
        table: null
    },
    init:function(){
        var _self = this;
        layui.use(['layer'], function(){
            layer = layui.layer;
        });
        this.$nextTick(function() {
            this.$http.post("../OutConfirm/dadiOutConfirmList",{},{emulateJSON: true}).then(function(res){
                if(res.ok){
                    _self.tableData = res.body.Stocks;
                    _self.$options.methods.renderTable(_self,res.body.Stocks);
                }
            });
        });
    },
    methods: {
        saveLists: function(data){
            var _self = this;
            var WLIDS = "";
            var SIZEIDS = "";
            var COLORIDS = "";
            var DWIDS = "";
            var MXQTYS = "";
            var CKIDS = "";
            var LLIDS = "";
            var LLCODES = "";
            var LISTIDS = "";
            var checkStatus = _self.table.checkStatus("efficiencyTable");
            var data = checkStatus.data;
            if (data.length > 0) {

                for (var i = 0;i < data.length;i ++) {
                    WLIDS = WLIDS +data[i].WLID+",";
                    SIZEIDS = SIZEIDS +data[i].CMID+",";
                    COLORIDS = COLORIDS +data[i].YSID+",";
                    DWIDS = DWIDS +data[i].DWID+",";
                    MXQTYS = MXQTYS +data[i].MXQTY+",";
                    CKIDS = CKIDS +data[i].CKID+",";
                    LLIDS = LLIDS +data[i].LLID+",";
                    LLCODES = LLCODES +data[i].LLCODE+",";
                    LISTIDS = LISTIDS +data[i].LISTID+",";

                }
            }

            var data ={
                WLIDS : WLIDS,
                SIZEIDS : SIZEIDS,
                COLORIDS : COLORIDS,
                DWIDS : DWIDS,
                MXQTYS : MXQTYS,
                CKIDS : CKIDS,
                LLIDS : LLIDS,
                LLCODES : LLCODES,
                LISTIDS : LISTIDS
            };

            this.$nextTick(function() {
                this.$http.post("../OutConfirm/SaveOutConfirmLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.result = res.body.results;
                        _self.products = res.body.product;

                        if(_self){

                        }

                        if(_self.result == "false"){
                            layer.msg("领料失败");
                        }else if(_self.result == "last1"){
                            layer.msg("物料编码为"+_self.products +"的领用数量超过该物料的库存数量");

                        }else if( _self.result == "oldresults"){
                            layer.msg("物料编码为"+_self.products +"无库存！");
                        }else{
                            layer.msg("领料成功！");
                            window.setTimeout(function() {
                                window.location.reload();
                            }, 1000);
                        }

                    }else{
                        layer.msg("领料失败");
                    }
                });
            });
        },
        SelectLists: function(data){
            var _self = this;

            var llcode = document.getElementById("llcode").value;   //物料编码
            var colors = document.getElementById("color").value;  //颜色
            var wlnames = document.getElementById("wlname").value;   //物料名称
            var sizes = document.getElementById("size").value;	//尺寸

            var data ={
                llcode : llcode,
                colors : colors,
                wlname : wlnames,
                sizes : sizes
            };

            this.$nextTick(function() {
                this.$http.post("../OutConfirm/dadiOutConfirmLists",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.condition = res.body.Lists;
                        _self.$options.methods.renderTable(_self,res.body.Lists);

                    }else{
                        layer.msg("查询失败");
                    }
                });
            });
        },
        reset:function(data){
            window.location.reload();
        },
        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        },
        renderTable: function(_self,data){
            layui.use(['form','table','laydate'], function(){
                _self.table = layui.table;
                var form = layui.form;

                _self.table.render({
                    elem: '#efficiencyTable',
                    height: 'full-100',
                    cols: [[ //标题栏
                        { fixed:'left',type:'checkbox'},
                        { type:'numbers',title:'序号'},
                      //  {field: 'LEFTS', title: '左右脚', width:80,align:'center'},
                        { field: 'LLCODE', title: '领料单号',minWidth:120,width:140},
                        { field: 'WLCODE', title: '物料编码',minWidth:120,width:140},
                        {field: 'WLNAME', title: '物料名称',minWidth:120,width:150, align:'center' },
                        {field: 'MXQTY', title: '领用数量', width:120,align:'center'},
                        {field: 'BDQTY', title: '已绑RFID数量', width:120,align:'center'},
                        {field: 'DWNAME', title: '单位', width:80,align:'center'},
                        {field: 'CZNAME', title: '材质', width:150,align:'center'},
                        {field: 'YSNAME', title: '颜色', width:150,align:'center'},
                        {field: 'CMCODE', title: '尺码', width:80,align:'center'},
                        {field: 'MBNAME', title: '目标仓库', width:150,align:'center'}
                        //,{fixed: 'right', title: '操作', align: 'center', toolbar: '#DadiOutofstocklist'}
                    ]],
                    data:data,
                    page: true, //是否显示分页
                    limits: [10, 20, 50],
                    limit: 15 //每页默认显示的数量
                });

                //监听工具条
                _self.table.on('tool(DadiOutofstocklistfuntion)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                    var row = obj.data //获得当前行数据
                        ,layEvent = obj.event; //获得 lay-event 对应的值
                   /* if(layEvent == 'rfid'){
                        _self.writeRfid(row);
                    }*/
                });
            });
        }/*,
        writeRfid: function(row) {
            var _self = this;
            var data ={
                LLID:row.LISTID,
                MXQTYS :row.MXQTY,
                BDQTY:row.BDQTY,
                WLID:row.WLID,
                CMID:row.CMID,
              //  LEFTS:row.LEFTS,
                YSID:row.YSID
            };
            this.$nextTick(function() {
                this.$http.post(host +"OutConfirm/updateJobStatus",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){

                        _self.result = res.body.results;
                        _self.products = res.body.product;
                        _self.RFIDCODE = res.body.RFIDCODE;

                        if(_self.result == "false"){
                            layer.msg("写入失败");
                        }else if( _self.result == "oldresults"){
                            layer.msg("该物料无库存！");
                        }else{
                            layer.msg("写入成功！");
                            top.layer.open({
                                type: 2,
                                title: "写入RFID",
                                shadeClose: true,
                                shade: 0.6,
                                area: ['300', '120'],
                                fixed:true,
                                content: 'http://localhost:28088/xdRfid/write?rfid=' + _self.RFIDCODE,
                                end:function(){
                                }
                            });
                            window.setTimeout(function() {
                                window.location.reload();
                            }, 1000);
                        }
                    }else{
                        layer.msg("写入失败");
                    }
                });
            });
        }*/
    }
});